﻿<select value="@Value"
        @onchange="OnOptionSelected"
        class="input bg-dark-550 w-full @CssClass">
    @if (Placeholder != null)
    {
        <option value="-1">@Placeholder</option>
    }
    @foreach (var (id, name) in Values)
    {
        <option value="@id" class="text-grey-400">@name</option>
    }
</select>

@code
{
    [Parameter]
    public IDictionary<int, string> Values { get; set; }

    [Parameter]
    public Action<int> OnChange { get; set; }

    [Parameter]
    public int Value { get; set; }

    [Parameter]
    public EventCallback<int> ValueChanged { get; set; }

    [Parameter]
    public string CssClass { get; set; }

    [Parameter]
    public string Placeholder { get; set; }

    private async Task OnOptionSelected(ChangeEventArgs e)
    {
        Value = int.Parse(e.Value?.ToString() ?? "-1");
        await ValueChanged.InvokeAsync(Value);
        OnChange?.Invoke(Value);
    }
}